<?php

namespace app\uniapp\controller;

use app\model\site\User;
use app\uniapp\middleware\CheckLogin;
use app\uniapp\service\UniAuthService;
use app\uniapp\service\UserService;
use think\Request;

class UserConfigController extends UniController
{
    protected array $middleware = [
        CheckLogin::class,
    ];
    public function bindMobile(Request $request): \think\response\Json
    {
        $mobile = $request->post("mobile");
        $sms = $request->post('sms');
        // todo: 验证短信验证码

        // todo: 修改手机号
        $user = UserService::instance()->setWhere([
            ['mobile', '=', $mobile]
        ])
            ->find();
        if ($user && $user->id != UniAuthService::instance()->getLoginId()){
            return jsonError("手机号已被占用");
        }
        $this->user->mobile = $mobile;
        $this->user->save();
        return jsonSuccess();

    }
}
